|
1
|
|
|
/*! |
|
2
|
|
|
* @author Semenov Alexander <[email protected]> |
|
3
|
|
|
* @link http://skeeks.com/ |
|
4
|
|
|
* @copyright 2010 SkeekS (СкикС) |
|
5
|
|
|
* @date 09.06.2015 |
|
6
|
|
|
*/ |
|
7
|
|
|
(function(sx, $, _) |
|
8
|
|
|
{ |
|
9
|
|
|
sx.createNamespace('classes.combotext', sx); |
|
10
|
|
|
sx.createNamespace('classes.combotext.controlls', sx); |
|
11
|
|
|
|
|
12
|
|
|
sx.classes.combotext.controlls._Base = sx.classes.Component.extend({ |
|
13
|
|
|
|
|
14
|
|
|
construct: function (ComboTextInputWidget, opts) |
|
15
|
|
|
{ |
|
16
|
|
|
var self = this; |
|
|
|
|
|
|
17
|
|
|
opts = opts || {}; |
|
18
|
|
|
if (!ComboTextInputWidget instanceof sx.classes.combotext.ComboTextInputWidget) |
|
19
|
|
|
{ |
|
20
|
|
|
throw new Error('Некорректный виджет для этого контрола'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
this.widget = ComboTextInputWidget; |
|
24
|
|
|
//this.parent.construct(opts); |
|
25
|
|
|
this.applyParentMethod(sx.classes.Component, 'construct', [opts]); // TODO: make a workaround for magic parent calling |
|
26
|
|
|
}, |
|
27
|
|
|
|
|
28
|
|
|
_init: function() |
|
29
|
|
|
{}, |
|
30
|
|
|
|
|
31
|
|
|
run: function() |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
}, |
|
35
|
|
|
|
|
36
|
|
|
stop: function() |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
}, |
|
40
|
|
|
}); |
|
41
|
|
|
|
|
42
|
|
|
sx.classes.combotext.controlls.Ckeditor = sx.classes.combotext.controlls._Base.extend({ |
|
43
|
|
|
|
|
44
|
|
|
_init: function() |
|
45
|
|
|
{ |
|
46
|
|
|
this.ckeditorInited = false; |
|
47
|
|
|
}, |
|
48
|
|
|
|
|
49
|
|
|
run: function() |
|
50
|
|
|
{ |
|
51
|
|
|
var self = this; |
|
52
|
|
|
|
|
53
|
|
|
this.onWindowReady(function() |
|
54
|
|
|
{ |
|
55
|
|
|
self._run(); |
|
56
|
|
|
}); |
|
57
|
|
|
}, |
|
58
|
|
|
|
|
59
|
|
|
_run: function() |
|
60
|
|
|
{ |
|
61
|
|
|
CKEDITOR.replace(this.widget.get('inputId'), _.extend({ |
|
|
|
|
|
|
62
|
|
|
// allowedContent: true, |
|
63
|
|
|
}, this.widget.get('ckeditor')) ); |
|
64
|
|
|
|
|
65
|
|
|
this.getInstance().updateElement(); |
|
66
|
|
|
//При первом запуске будет запущен этот код. |
|
67
|
|
|
if (this.ckeditorInited === false) |
|
68
|
|
|
{ |
|
69
|
|
|
skeeks.ckEditorWidget.registerOnChangeHandler(this.get('inputId')); |
|
|
|
|
|
|
70
|
|
|
if (this.widget.get('ckeditor').filebrowserUploadUrl) |
|
71
|
|
|
{ |
|
72
|
|
|
skeeks.ckEditorWidget.registerCsrfImageUploadHandler(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
//TODO: Это не работает, нужно дорабатывать. |
|
76
|
|
|
CKEDITOR.config.protectedSource.push( /<\?[\s\S]*?\?>/g ); // PHP code |
|
77
|
|
|
CKEDITOR.config.protectedSource.push( /<%[\s\S]*?%>/g ); // ASP code |
|
78
|
|
|
CKEDITOR.config.protectedSource.push( /(<asp:[^\>]+>[\s|\S]*?<\/asp:[^\>]+>)|(<asp:[^\>]+\/>)/gi ); // ASP.Net code |
|
79
|
|
|
CKEDITOR.config.protectedSource.push(/<(style)[^>]*>.*<\/style>/ig); |
|
80
|
|
|
CKEDITOR.config.protectedSource.push(/<(script)[^>]*>.*<\/script>/ig);// разрешить теги <script> |
|
81
|
|
|
CKEDITOR.config.protectedSource.push(/<\?[\s\S]*?\?>/g);// разрешить php-код |
|
82
|
|
|
CKEDITOR.config.protectedSource.push(/<!--dev-->[\s\S]*<!--\/dev-->/g); |
|
83
|
|
|
CKEDITOR.config.allowedContent = true; /* all tags */ |
|
84
|
|
|
|
|
85
|
|
|
this.ckeditorInited = true; |
|
86
|
|
|
} |
|
87
|
|
|
}, |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* |
|
91
|
|
|
* @returns {sx.classes.combotext.controlls.ControllCkeditor} |
|
92
|
|
|
*/ |
|
93
|
|
|
stop: function() |
|
94
|
|
|
{ |
|
95
|
|
|
if (this.getInstance()) |
|
96
|
|
|
{ |
|
97
|
|
|
this.getInstance().destroy(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return this; |
|
101
|
|
|
}, |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* |
|
105
|
|
|
* @returns {CKEDITOR.editor} |
|
106
|
|
|
*/ |
|
107
|
|
|
getInstance: function() |
|
108
|
|
|
{ |
|
109
|
|
|
return CKEDITOR.instances[this.widget.get('inputId')]; |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
}); |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
sx.classes.combotext.controlls.Codemirror = sx.classes.combotext.controlls._Base.extend({ |
|
116
|
|
|
|
|
117
|
|
|
_init: function() |
|
118
|
|
|
{ |
|
119
|
|
|
this.Instance = null; |
|
120
|
|
|
}, |
|
121
|
|
|
|
|
122
|
|
|
run: function() |
|
123
|
|
|
{ |
|
124
|
|
|
var self = this; |
|
125
|
|
|
this.Instance = CodeMirror.fromTextArea(document.getElementById(this.widget.get('inputId'))); |
|
|
|
|
|
|
126
|
|
|
var options = this.widget.get('codemirror'); |
|
127
|
|
|
if (options) |
|
128
|
|
|
{ |
|
129
|
|
|
_.each(options, function(val, key) |
|
130
|
|
|
{ |
|
131
|
|
|
self.Instance.setOption(key, val); |
|
132
|
|
|
}); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
self.Instance.focus(); |
|
136
|
|
|
|
|
137
|
|
|
return this; |
|
138
|
|
|
}, |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* |
|
143
|
|
|
* @returns {sx.classes.combotext.controlls.ControllCkeditor} |
|
144
|
|
|
*/ |
|
145
|
|
|
stop: function() |
|
146
|
|
|
{ |
|
147
|
|
|
if (this.Instance) |
|
148
|
|
|
{ |
|
149
|
|
|
this.Instance.save(); |
|
150
|
|
|
this.Instance.display.wrapper.remove(); |
|
151
|
|
|
|
|
152
|
|
|
$("#" + this.widget.get('inputId')).show(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
return this; |
|
156
|
|
|
}, |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
}); |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
//Основной объект |
|
163
|
|
|
sx.classes.combotext.ComboTextInputWidget = sx.classes.Component.extend({ |
|
164
|
|
|
|
|
165
|
|
|
_init: function() |
|
166
|
|
|
{ |
|
167
|
|
|
this.ControllCkeditor = new sx.classes.combotext.controlls.Ckeditor(this); |
|
168
|
|
|
this.ControllCodemirror = new sx.classes.combotext.controlls.Codemirror(this); |
|
169
|
|
|
this.currentControll = null; |
|
170
|
|
|
}, |
|
171
|
|
|
|
|
172
|
|
|
_onDomReady: function() |
|
173
|
|
|
{ |
|
174
|
|
|
var self = this; |
|
175
|
|
|
this.jQueryWrapper = $('#' + this.get('id')); |
|
176
|
|
|
|
|
177
|
|
|
$(".sx-select-controll input[type=radio]", this.jQueryWrapper).on('change', function() |
|
178
|
|
|
{ |
|
179
|
|
|
self.goControll($(this).val()); |
|
180
|
|
|
return false; |
|
181
|
|
|
}); |
|
182
|
|
|
|
|
183
|
|
|
self.goControll($(".sx-select-controll input[type=radio]:checked", this.jQueryWrapper).val()); |
|
184
|
|
|
}, |
|
185
|
|
|
|
|
186
|
|
|
goControll: function(code) |
|
187
|
|
|
{ |
|
188
|
|
|
if (this.currentControll) |
|
189
|
|
|
{ |
|
190
|
|
|
this.currentControll.stop(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
if (code == 'editor') |
|
194
|
|
|
{ |
|
195
|
|
|
this.currentControll = this.ControllCkeditor; |
|
196
|
|
|
this.ControllCkeditor.run(); |
|
197
|
|
|
|
|
198
|
|
|
} else if (code == 'text') |
|
199
|
|
|
{ |
|
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
} else if (code == 'html') |
|
202
|
|
|
{ |
|
203
|
|
|
this.currentControll = this.ControllCodemirror; |
|
204
|
|
|
this.ControllCodemirror.run(); |
|
205
|
|
|
} else |
|
206
|
|
|
{ |
|
207
|
|
|
//sx.notify.error('Еще не реализовано'); |
|
208
|
|
|
} |
|
209
|
|
|
}, |
|
210
|
|
|
|
|
211
|
|
|
}); |
|
212
|
|
|
|
|
213
|
|
|
})(sx, sx.$, sx._); |
|
|
|
|
|